﻿// -----------------------------------------------------------------------------
//   Copyright (c) SRT Solutions 2009. All rights reserved.
// -----------------------------------------------------------------------------

namespace SRTSolutions.Elevate
{
    using global::System;
    using global::System.Diagnostics;

    /// <summary>
    /// Contains utilities for timing things.
    /// </summary>
    public static class Timing
    {
        /// <summary>
        /// Returns the wall time that it takes to run the specified action.
        /// </summary>
        /// <param name="action">The action to time.</param>
        /// <returns>
        /// The wall time that it takes to run the specified action
        /// </returns>
        public static TimeSpan Time(this Action action)
        {
            if (action == null)
                throw new ArgumentNullException("action", "action is null.");

            var watch = Stopwatch.StartNew();
            action();
            watch.Stop();
            return watch.Elapsed;
        }
    }
}
